package com.mask.im.business.common.util;

import com.mask.im.business.model.dto.EmailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Component
public class CommonUtil {

	@Autowired
	private EmailUtil emailUtil;

//	@Value("${spring.mail.username}")
	private String email;


	public void signUpNotifications(String username,String signUpType){
		Map<String, Object> map = new HashMap<>();
		map.put("content", "《用户注册通知》用户名为: <span style=\"font-weight:700\">" + username + "</span> " +
				"的用户于"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
				+"使用<span style=\"font-weight:700;color:red\">"+ signUpType + "</span>进行了注册");
		EmailDTO emailDTO = EmailDTO.builder()
				.template("common.html")
				.email(email)
				.subject("用户注册通知")
				.commentMap(map).build();
		emailUtil.sendHtmlMail(emailDTO);
	}
}
